package com.lichuang.fruitvarietysm.manage.controller;


import com.lichuang.fruitvarietysm.manage.entity.User;
import com.lichuang.fruitvarietysm.manage.feignclient.UserFeignClient;
import com.lichuang.fruitvarietysm.manage.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author shuaihang
 * @since 2019-07-06
 */
@RestController
@RequestMapping("//user")
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private UserFeignClient userFeignClient;

    @RequestMapping("/login")
    public User login(User userParam, HttpServletResponse response) {
        User user = userService.queryAdminUser(userParam);
        userService.saveUserWithRedis(user, response);
        return user;
    }

    @RequestMapping("/getCurrentUser")
    public User getCurrentUser(@CookieValue String loginToken) {
        return userFeignClient.getCurrentUser(loginToken);
    }

}
